using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

namespace NetDIYTest
{
    class DebugHelper
    {
        //private static byte[] UnicodeByteBuffer = new byte[2];
        public static string Byte2Hex(byte value)
        {
            const string hex = "0123456789ABCDEF";
            int high = value >> 4;
            int low = value & 0x0F;
            return "0x" + new string(new char[] { hex[high], hex[low] });
        }

        //private static string HalfByte2Hex(int value)
        //{
        //    if (value<10)
        //    {
        //        return value.ToString();
        //    }
        //    else
        //    {
        //        UnicodeByteBuffer[1]=(byte)(value-10+41);
        //        return System.Text.Encoding.UTF8.GetChars(UnicodeByteBuffer).ToString();
        //    }
        //}

        public static string Byte2Bit(byte value)
        {
            string output = string.Empty;
            for (int i = 0; i < 8; i++)
            {
                output += (value >> (8 - i + 1) > 0) ? "1" : "0";
            }
            return output;
        }
    }
    class BypassSwitch
    {
        OutputPort oPin ;
        InputPort iPin;
        public BypassSwitch(Cpu.Pin outputPin, Cpu.Pin inputPin )
        {
            oPin = new OutputPort(outputPin,false);
            iPin = new InputPort(inputPin,false,Port.ResistorMode.PullDown);
        }
        public bool Test()
        {
            oPin.Write(true);
            return iPin.Read();
        }
    }
}
